WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
isometry_conversions.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20#pragma once
21
22#include "core/common/wolf.h"
24#include "core/math/rotations.h"
25
26namespace wolf
27{
28template <typename D1>
29inline Eigen::Transform<typename D1::Scalar, 2, Eigen::Isometry> toIsometry2d(const Eigen::MatrixBase<D1>& translation,
30 const double& rotation)
31{
33
34 return Eigen::Translation<typename D1::Scalar, 2>(translation) * Eigen::Rotation2D<typename D1::Scalar>(rotation);
35}
36
37template <typename D1, typename D2>
38inline Eigen::Transform<typename D1::Scalar, 2, Eigen::Isometry> toIsometry2d(const Eigen::MatrixBase<D1>& translation,
39 const Eigen::MatrixBase<D2>& rotation)
40{
43
44 return toIsometry2d(translation, rotation(0));
45}
46
47template <typename D1>
48inline Eigen::Transform<typename D1::Scalar, 2, Eigen::Isometry> toIsometry2d(const Eigen::MatrixBase<D1>& trf)
49{
51
52 return toIsometry2d(Eigen::Matrix<typename D1::Scalar, 2, 1>(trf(0), trf(1)), trf(2));
53}
54
55inline Eigen::Isometry2d toIsometry2d(const VectorComposite& trf)
56{
57 return toIsometry2d(trf.at('P'), trf.at('O'));
58}
59
60template <typename D1, typename D2>
61inline Eigen::Transform<typename D1::Scalar, 3, Eigen::Isometry> toIsometry3d(
62 const Eigen::MatrixBase<D1>& translation,
63 const Eigen::QuaternionBase<D2>& rotation)
64{
66
67 return Eigen::Translation<typename D1::Scalar, 3>(translation) * rotation;
68}
69
70template <typename D1, typename D2>
71inline Eigen::Transform<typename D1::Scalar, 3, Eigen::Isometry> toIsometry3d(const Eigen::MatrixBase<D1>& translation,
72 const Eigen::MatrixBase<D2>& rotation)
73{
76
77 return toIsometry3d(
78 translation,
79 Eigen::Quaternion<typename D2::Scalar>(Eigen::Matrix<typename D2::Scalar, 4, 1>(rotation).normalized()));
80}
81
82template <typename D1>
83inline Eigen::Transform<typename D1::Scalar, 3, Eigen::Isometry> toIsometry3d(const Eigen::MatrixBase<D1>& trf)
84{
86 return toIsometry3d(Eigen::Matrix<typename D1::Scalar, 3, 1>(trf(0), trf(1), trf(2)),
87 Eigen::Quaternion<typename D1::Scalar>(trf(6), trf(3), trf(4), trf(5)));
88}
89
90inline Eigen::Isometry3d toIsometry3d(const VectorComposite& trf)
91{
92 return toIsometry3d(trf.at('P'), trf.at('O'));
93}
94
95inline Eigen::Vector3d toVector(const Eigen::Isometry2d& trf)
96{
97 return (Eigen::Vector3d() << trf.translation(), Eigen::Rotation2Dd(trf.rotation()).angle()).finished();
98}
99
100inline Eigen::Vector7d toVector(const Eigen::Isometry3d& trf)
101{
102 return (Eigen::Vector7d() << trf.translation(), Eigen::Quaterniond(trf.rotation()).coeffs().normalized())
103 .finished();
104}
105
106inline Eigen::Isometry3d inverseProjectTo3d(const Eigen::Isometry2d& trf_2d)
107{
108 return Eigen::Translation3d((Eigen::Vector3d() << trf_2d.translation(), 0).finished()) *
109 Eigen::AngleAxisd(Eigen::Rotation2Dd(trf_2d.rotation()).angle(), Eigen::Vector3d::UnitZ());
110}
111
112inline Eigen::Isometry2d projectTo2d(const Eigen::Isometry3d& trf_3d)
113{
114 return Eigen::Translation2d(trf_3d.translation().head<2>()) *
115 Eigen::Rotation2Dd(getYaw(trf_3d.rotation().matrix()));
116}
117
118} // namespace wolf
Definition: vector_composite.h:27
Matrix< double, 7, 1 > Vector7d
7-vector of real double type
Definition: wolf.h:106
Definition: capture_base.h:23
Eigen::Transform< typename D1::Scalar, 2, Eigen::Isometry > toIsometry2d(const Eigen::MatrixBase< D1 > &translation, const double &rotation)
Definition: isometry_conversions.h:29
Eigen::Transform< typename D1::Scalar, 3, Eigen::Isometry > toIsometry3d(const Eigen::MatrixBase< D1 > &translation, const Eigen::QuaternionBase< D2 > &rotation)
Definition: isometry_conversions.h:61
Eigen::Isometry3d inverseProjectTo3d(const Eigen::Isometry2d &trf_2d)
Definition: isometry_conversions.h:106
Eigen::Isometry2d projectTo2d(const Eigen::Isometry3d &trf_3d)
Definition: isometry_conversions.h:112
Eigen::MatrixBase< Derived >::Scalar getYaw(const Eigen::MatrixBase< Derived > &_M)
Definition: rotations.h:223
Eigen::Vector3d toVector(const Eigen::Isometry2d &trf)
Definition: isometry_conversions.h:95
static void check(const T &t)
Assert matrix size dynamically or statically.
Definition: wolf.h:187